package com.example.compreshensiveshop.controller;

import com.example.compreshensiveshop.dto.OrderCreateDTO;
import com.example.compreshensiveshop.service.OrdersService;
import com.example.compreshensiveshop.vo.*;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    /**
     * 获取订单编号
     * @param customerId
     * @return
     */
    @GetMapping("/getOrderNumber")
    public OrderNumberVO getOrderNumber(@RequestParam Long customerId){
        return ordersService.getOrderNumber(customerId);
    }
    /**
     * 创建订单
     * @param orderCreateDTO
     * @return
     */
    @PostMapping("/addOrder")
    public OrderCreateVO addOrder(@RequestBody OrderCreateDTO orderCreateDTO){
        return ordersService.addOrder(orderCreateDTO);
    }
    /**
     * 获取用户订单
     * @param pageNum
     * @param pageSize
     * @param customerId
     * @param status
     * @return
     */
    @GetMapping("/getCustomerOrder")
    public PageInfo<OrderCustomerVO> getCustomerOrder(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam Long customerId, @RequestParam(required = false) Integer status){
        return ordersService.getCustomerOrder(pageNum, pageSize, customerId, status);
    }
    /**
     * 获取商家订单
     * @param pageNum
     * @param pageSize
     * @param sellerId
     * @param status
     * @param keyword
     * @param itemStatus
     * @return
     */
    @GetMapping("/getSellerOrder")
    public PageInfo<OrderSellerList> getSellerOrder(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam Long sellerId,
                                                    @RequestParam(required = false) Integer status,
                                                    @RequestParam(required = false) String keyword,
                                                    @RequestParam(required = false) Integer itemStatus){
        return ordersService.getSellerOrder(pageNum, pageSize, sellerId, status, keyword, itemStatus);
    }
    /**
     * 查询订单信息
     * @param orderId
     * @return
     */
    @GetMapping("/queryOrderMessage")
    public OrderCustomerVO queryOrderMessage(@RequestParam Long orderId){
        return ordersService.queryOrderMessage(orderId);
    }
    /**
     * 查询订单日销售
     * @param sellerId
     * @param year
     * @param month
     * @return
     */
   @GetMapping("/queryDailySales")
    public List<DailySalesVO> queryDailySales(@RequestParam Long sellerId, @RequestParam Integer year ,@RequestParam Integer month){
        return ordersService.queryDailySales( sellerId, year, month);
    }
    /**
     * 查询订单月销售
     * @param sellerId
     * @param year
     * @return
     */
    @GetMapping("/queryMonthlySales")
    public List<MonthlySalesVO> queryMonthLySales(@RequestParam Long sellerId, @RequestParam Integer year){
        return ordersService.queryMonthLySales( sellerId, year);
    }
    /**
     * 修改订单状态
     * @param orderId
     * @param status
     */
    @PutMapping("/updateOrderStatus")
    public void updateOrderStatus(@RequestParam Long orderId, @RequestParam Integer status){
        ordersService.updateOrderStatus(orderId, status);
    }
    /**
     * 发货
     * @param orderId
     */
    @PutMapping("/deliverOrder")
    public void deliverOrder(@RequestParam Long orderId,@RequestParam Long ItemId){
        ordersService.deliverOrder(orderId, ItemId);
    }
}